# -*- coding: utf-8 -*-
from datetime import timedelta


from jms.dwd.september.dwd_tab_end_piece_unprocessed_dt import jms_dwd__dwd_tab_end_piece_unprocessed_dt
from jms.ods.oms.yl_oms_interceptorpiece import jms_ods__yl_oms_interceptorpiece
from jms.dwd.oms.dwd_yl_oms_interceptorpiece_base import jms_dwd__dwd_yl_oms_interceptorpiece_base
from jms.dwd.tab.dwd_tab_barscan_other_base_dt import jms_dwd__dwd_tab_barscan_other_base_dt
from jms.dwd.tab.dwd_tab_barscan_sign_base_dt import jms_dwd__dwd_tab_barscan_sign_base_dt
from jms.dwd.tab.dwd_tab_barscan_deliver_base_dt import jms_dwd__dwd_tab_barscan_deliver_base_dt
from jms.dwd.tab.dwd_tab_barscan_warehousing_base_dt import jms_dwd__dwd_tab_barscan_warehousing_base_dt
from jms.dwd.tab.dwd_tab_barscan_bagging_base_dt import jms_dwd__dwd_tab_barscan_bagging_base_dt
from jms.dwd.tab.dwd_tab_barscan_send_base_dt import jms_dwd__dwd_tab_barscan_send_base_dt
from jms.dwd.tab.dwd_tab_barscan_loading_base_dt import jms_dwd__dwd_tab_barscan_loading_base_dt
from jms.dwd.tab.dwd_tab_barscan_arrival_base_dt import jms_dwd__dwd_tab_barscan_arrival_base_dt
from jms.dwd.tab.dwd_tab_barscan_unloading_base_dt import jms_dwd__dwd_tab_barscan_unloading_base_dt
from jms.dwd.tab.dwd_tab_barscan_difficult_base_dt import jms_dwd__dwd_tab_barscan_difficult_base_dt
from jms.dwd.tab.dwd_tab_barscan_collect_base_dt import jms_dwd__dwd_tab_barscan_collect_base_dt
from jms.dwd.tab.dwd_tab_barscan_taking_base_dt import jms_dwd__dwd_tab_barscan_taking_base_dt
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

jms_dws__dws_end_piece_trace_track_dt = SparkSqlOperator(
    task_id='jms_dws__dws_end_piece_trace_track_dt',
    email=['lukunming@jtexpress.com','yl_bigdata@yl-scm.com'],
    depends_on_past=True,
    pool_slots=4,
    master='yarn',
    execution_timeout=timedelta(minutes=60),
    priority_weight=8,
    name='jms_dws__dws_end_piece_trace_track_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dws/september/dws_end_piece_trace_track_dt/execute.hql',
    executor_cores=4,
    executor_memory='10G',
    num_executors=5,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          #'spark.dynamicAllocation.maxExecutors': 20,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.maxExecutors': 14,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '1G',  # 堆外内存
          },
#     hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
#               'hive.exec.dynamic.partition.mode': 'nonstrict',
#               'hive.exec.max.dynamic.partitions': 3,  # 每天生成 20 个分区
#               'hive.exec.max.dynamic.partitions.pernode': 3,  # 每天生成 20 个分区
#               },
)

jms_dws__dws_end_piece_trace_track_dt << [
    jms_dwd__dwd_tab_barscan_other_base_dt,
    jms_dwd__dwd_tab_barscan_sign_base_dt,
    jms_dwd__dwd_tab_barscan_deliver_base_dt,
    jms_dwd__dwd_tab_barscan_warehousing_base_dt,
    jms_dwd__dwd_tab_barscan_bagging_base_dt,
    jms_dwd__dwd_tab_barscan_send_base_dt,
    jms_dwd__dwd_tab_barscan_loading_base_dt,
    jms_dwd__dwd_tab_barscan_arrival_base_dt,
    jms_dwd__dwd_tab_barscan_unloading_base_dt,
    jms_dwd__dwd_tab_barscan_difficult_base_dt,
    jms_dwd__dwd_tab_barscan_collect_base_dt,
    jms_dwd__dwd_tab_barscan_taking_base_dt,
    jms_dwd__dwd_yl_oms_interceptorpiece_base,
    jms_dwd__dwd_tab_end_piece_unprocessed_dt
]
